/** @format */

const packages = require('../package.json');
const rules = require('./lib/rules');
const performance = require('./lib/performance');
const optimization = require('./lib/optimization');
const config = require('./lib/config');

const {
  getPath, DIST, PATH_SRC, MATCH_NODE_MODULES,
} = config;

module.exports = {
	target: 'web',
	stats: 'errors-only',
  entry: {
    main: getPath('src/index.tsx'),
  },
  output: {
    filename: 'js/[name].[contenthash:8].js',
    path: DIST,
    chunkFilename: 'js/[name].[contenthash:8].js',
    publicPath: '',
  },
  // infrastructureLogging: {
  //   level: 'error'
  // },
  stats: {
    all: false,
    assets: true,
    errors: true,
    assetsSort: '!size',
    entrypoints: true,
    modules: false,
    assetsSpace: 1000,
    preset: 'minimal',
	},
	optimization,
  resolve: {
    alias: {
      src: PATH_SRC,
      components: getPath('src/components'),
      utils: getPath('src/utils'),
      '@': PATH_SRC,
    },
    extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'],
  },
  module: {
    rules,
  },
  watchOptions: {
    // 设置不监听的⽂件或⽂件夹，默认为空
    ignored: MATCH_NODE_MODULES,
    // ⽂件改变不会⽴即执⾏，⽽是会等待300ms之后再去执⾏
    aggregateTimeout: 300,
    // 原理是轮询系统⽂件有⽆变化再去更新的，默认1秒钟轮询1000次
    poll: 1000,
  },
  performance,
};
